<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
	<title>CSP Citizen map</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script>
	<script type="text/javascript">

	var map = null;
	var position = null;
      
	function HandleClick(e)
	{
		position = map.PixelToLatLong(new VEPixel(e.clientX, e.clientY));
		map.SetCenter(position);
		map.DeleteAllShapes();
		AddPushpin();
		var crmForm = parent.document.forms[0];
		crmForm.all.address1_latitude.DataValue = position.Latitude;
		crmForm.all.address1_longitude.DataValue = position.Longitude;
	}
    
	function GetCRMCoordinates()
	{
		var crmForm = parent.document.forms[0];
		position = new VELatLong();
		if ((crmForm.all.address1_latitude.DataValue != null) && (crmForm.all.address1_longitude.DataValue != null))
		{
			position.Latitude = crmForm.all.address1_latitude.DataValue;
			position.Longitude = crmForm.all.address1_longitude.DataValue;
			map.SetCenter(position);
			map.SetZoomLevel(9);
			AddPushpin();
		}
	}	

	function AddPushpin()
	{
		var shape = new VEShape(VEShapeType.Pushpin, position);
		shape.SetTitle('Address'); 
		map.AddShape(shape);
	}
	
	function GetMap()
	{
		map = new VEMap('veMap');
		map.LoadMap();
		setTimeout(GetCRMCoordinates, 100);
		map.AttachEvent("ondoubleclick", HandleClick);	 
	}
	
	
    </script>
   </head>
   <body onload="GetMap();">
      <div id='veMap' style="position:relative; width:700px; height:400px;"></div>
   </body>
</html>